package com.u17.service.impl;

import com.u17.dao.UserInfoMapper;
import com.u17.pojo.UserInfo;
import com.u17.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 秦川熙
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 账户金额递减
     * @param username
     * @param money
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void decrMoney(String username, int money) {
        //查询用户信息
        UserInfo userInfo = userInfoMapper.selectByPrimaryKey(username);
        //设置金额递减
        userInfo.setMoney(userInfo.getMoney() - money);
        //执行更新
        int count = userInfoMapper.updateByPrimaryKeySelective(userInfo);
        System.out.println("添加用户受影响数:" + count);
    }
}
